import random
def countingSort(A):
	N = len(A)
	B = [0] * (max(A) + 1)
	R = [0] * N

	for k in A:
		B[k] += 1

	for k in range(1, len(B)):
		B[k] += B[k - 1]

	for k in range(0, N):
		T = A.pop()
		R[B[T] - 1] = T
		B[T] -= 1

	return R



A = [random.randint(0, 20) for k in range(20)]

countingSort(A)